<?php
namespace app\index\controller;
use think\Db;
use think\Session;
use app\index\model\Inbox_model;
use think\Request;

class Inbox extends Common
{
    // 站内消息
    public function index()
    {
    	$rev = new Inbox_model;
        $res = $rev->getindex();
        // var_dump($res['mail']);die;
        return view('index@Inbox/index',[
            'node' => $res['list'],
            'amount' => $res['amount'],
            'num' => $res['num'],
            'num2' => $res['num2']
            // 'page' => $res['page']
        ]);

    }
    public function mail()
    {
        $rev = new Inbox_model;
        $res = $rev->getmail();

        // var_dump(123);
        // var_dump($res['all']);die;
        return view('index@Inbox/mail',[
            'node' => $res['node'],
            'all' => $res['all'],
            'num' => $res['num'],
            'num2' => $res['num2']
        ]);
    }

    //发送邮件
    public function send()
    {
        // var_dump($_POST);die;
        $rev = new Inbox_model;
        $res = $rev->sendMail();
       // var_dump($res);die;
       if ($res['a']) {
           $this->success('发送成功','inbox/index');
       }else{
           $this->error('发送失败','inbox/index');
       }
       // return view('index@Inbox/index',$res);
    }

    // 查看消息
    public function check($id)
    {
        $rev = new Inbox_model;
        $res = $rev->getMailinfo($id);
        // var_dump($res);die;
        return view('index@Inbox/checkmail',[
            'node' => $res['node'],
            'mailinfo' => $res['mailinfo'],
            'fj' => $res['fj'],
            'num' => $res['num'],
            'num2' => $res['num2']
        ]);
    }

    // 查看公告消息
    public function checkn($id)
    {
        $rev = new Inbox_model;
        $res = $rev->getnMailinfo($id);
        // var_dump($res['fjid']);die;
        return view('index@Inbox/checkn',[
            'node' => $res['node'],
            'mailinfo' => $res['mailinfo'],
            'fj' => $res['fjid']['0']['user_name'],
            'num' => $res['num'],
            'num2' => $res['num2'],
        ]);
    }
   
   // 查询已发消息
   public function checkalready($id)
   {
    $rev = new Inbox_model;
    $res = $rev->getMailalready($id);
    // var_dump($res);die;
        // fj  发件人
        return view('index@Inbox/email',[
            'node' => $res['node'],
            'mailinfo' => $res['mailinfo'],
            'sj' => $res['sj'],
            'num' => $res['num'],
            'num2' => $res['num2']
        ]);
   }

   // 已发送
   public function sent()
   {
    // var_dump(222);die;
    //查询已发送多少邮件
    $rev = new Inbox_model;
    $res = $rev->getSentmail();
    // var_dump($res['total']);die;
    return view('index@Inbox/sent',[
            'node' => $res['list'],
            'amount' => $res['amount'],
            'num' => $res['num'],
            'num2' => $res['num2'],
            'page' => $res['page']
        ]);
   }

   // 删除消息
   public function del()
   {
    // var_dump($_request);die;
    //先假设id是33
    // $id = 33;
    $id = $_POST['id'];
    // var_dump($id);die;
    // $id = $id.slice(1);
    // $code = array_splice($id, 0, "");
    // var_dump($id);die;
    $rev = new Inbox_model;
    $res = $rev->delMail($id);
    return $res;
        // if ($res == 1) {
        //     $this->success('删除成功','index/Inbox/index');
        // }else{
        //     $this->error('删除成功','index/Inbox/index');
        // }
   }

   //垃圾箱
   public function trash()
   {
    // 查询is_delete为1的有多少
    $rev = new Inbox_model;
    $res = $rev->getTrash();
    // var_dump($res['amount']);die;
    return view('index@Inbox/del',[
            'node' => $res['list'],
            'amount' => $res['amount'],
            'num' => $res['num'],
            'num2' => $res['num2'],
            'page' => $res['page']
        ]);
   }

   // 查询已删消息
   public function checkdel($id)
   {
    $rev = new Inbox_model;
    $res = $rev->getMaildel($id);
    // var_dump($res);die;
        // fj  发件人
        return view('index@Inbox/checkdel',[
            'node' => $res['node'],
            'mailinfo' => $res['mailinfo'],
            'sj' => $res['sj'],
            'num' => $res['num'],
            'num2' => $res['num2']
        ]);
   }

   public function search()
   {
    $rev = new Inbox_model;
    $res = $rev->getSearch();
    // var_dump($res['res']);die;
    return view('index@Inbox/searchResult',[
            'node' => $res['list'],
            'res' => $res['res'],
            'keyword' => $res['keyword'],
            'num' => $res['num'],
            'num2' => $res['num2'],
            'title' => $res['title']
        ]);
   }

   public function yfssearch()
   {
    $rev = new Inbox_model;
    $res = $rev->getyfsSearch();
    // var_dump($res['res']);die;
    return view('index@Inbox/searchResult',[
            'node' => $res['list'],
            'res' => $res['res'],
            'keyword' => $res['keyword'],
            'num' => $res['num'],
            'num2' => $res['num2'],
            'title' => $res['title']
        ]);
   }

   public function ljxsearch()
   {
    $rev = new Inbox_model;
    $res = $rev->getljxSearch();
    // var_dump($res['res']);die;
    return view('index@Inbox/searchResult',[
            'node' => $res['list'],
            'res' => $res['res'],
            'keyword' => $res['keyword'],
            'num' => $res['num'],
            'num2' => $res['num2'],
            'title' => $res['title']
        ]);
   }

   public function noticesearch()
   {
    $rev = new Inbox_model;
    $res = $rev->getnoticeSearch();
    // var_dump($res['res']);die;
    return view('index@Inbox/searchResult',[
            'node' => $res['list'],
            'res' => $res['res'],
            'keyword' => $res['keyword'],
            'num' => $res['num'],
            'num2' => $res['num2'],
            'title' => $res['title']
        ]);
   }


   //发布公告
   public function notice()
    {   
        // var_dump(222);die;
        $rev = new Inbox_model;
        $res = $rev->getNotice();

        // var_dump($res);die;
        return view('index@Inbox/notice',[
            'node' => $res['node'],
            'all' => $res['all'],
            'num' => $res['num'],
            'num2' => $res['num2']
        ]);
    }

    public function sendNotice()
    {
        $rev = new Inbox_model;
        $res = $rev->sendNotice();
        if ($res['a']) {
           $this->success('发送成功','inbox/index');
       }else{
           $this->error('发送失败','inbox/index');
       }
    }

    // 系统消息...就是公告
    public function checknotice()
    {
        $rev = new Inbox_model;
        $res = $rev->getAbnotice();
        // var_dump($res);die;
        return view('index@Inbox/checknotice',[
            'node' => $res['list'],
            'notice' => $res['notice'],
            'num' => $res['num'],
            'num2' => $res['num2']
            // 'page' => $res['page']
        ]);
    }


    public function restore()
    {
        $id = $_POST['id'];
        // var_dump($id);die;
        $rev = new Inbox_model;
        $res = $rev->restoreMail($id);
        return $res;
    }

    // 彻底删除
    public function findel()
    {
        $id = $_POST['id'];
       
        $rev = new Inbox_model;
        $res = $rev->finaldelMail($id);
        // var_dump($res);die;
        return $res;
    }

    // 回复消息
    public function replymail($id)
    {
        // var_dump($id);die;
        $rev = new Inbox_model;
        $res = $rev->replyMail($id);

        // var_dump($res);die;
        return view('index@Inbox/reply',[
            'node' => $res['node'],
            'num' => $res['num'],
            'num2' => $res['num2'],
            'mailinfo' => $res['mailinfo'],
            'fj' => $res['fj']
        ]);
    }

    // 转发消息
    public function forwardMail($id)
    {
        // var_dump($id);die;
        $rev = new Inbox_model;
        $res = $rev->forwardMail($id);

        // var_dump($res);die;
        return view('index@Inbox/forward',[
            'node' => $res['node'],
            'num' => $res['num'],
            'num2' => $res['num2'],
            'mailinfo' => $res['mailinfo'],
            'fj' => $res['fj']
        ]);
    }
    
 
}
